Program WordCount;

{ Die Kommentarklammern liegen rechts neben 'ß' ! }
{ Diese Demo stellt ein einfaches Unix "wc" Kommando dar }


Var fil               : Text;
    Buff,name         : String;
    Line,Size,ok : Boolean;
    AnzL,AnzS    : Integer;

Procedure ParseParams;
var Pa,s  : String;
    hi,i  : Integer;
Begin
 s:=ParamStr;
 ok:=True;
 if s=''
    then Begin
          Ok:=False;
          Writeln('wc [-lc] File')
         End
    else Begin
          I:=Pos('-',s);
          If i=0
             then Begin
                   Line:=True;
                   Size:=True;
                   Name:=s;
                   While (Length(s)>0) and (Copy(s,1,1)=' ') Do
                       s:=Copy(S,2,Length(s)-1);
                   i:=Pos(' ',s);
                   If i>0
                      then s:=Copy(s,1,i-1);
                   Name:=s
                  End
             else Begin
                   hI:=Pos(' ',s);
                   If hi=0
                      then ok:=False
                      else Begin
                            pa:=Copy(s,i,hi-i);
                            Line:=(Pos('l',pa)>0);
                            Size:=(Pos('c',pa)>0);
                            Name:=Copy(s,hi+1,Length(s)-hi)
                           End

                  End
         End
End;

Function GetSize: Integer;
Begin
 Return(FileSize(fil))
End;

Procedure Work;

Begin
 Reset(fil,Name);
 If IoResult=0
    then Begin
          AnzL:=0;
          If Size
             then AnzS:=GetSIze;
          While Not(eof(Fil)) Do
           Begin
            Readln(Fil,Buff);
            AnzL:=AnzL+1
           End;
          If Size
             then Write('Size :',AnzS,' ');
          If Line
             then Write('Lines : ',AnzL);
          Writeln;
          Close(Fil)
         End
End;

Begin
 ParseParams;
 If Ok
    then Work
End.
